#include <LPC11xx.h>
#include "rfid.h"
#include "serial.h"
#include <string.h>
int main()
{
	int i;
	unsigned char rbuf[16];
	unsigned char wbuf[16];
	
	LPC_SYSCON->SYSAHBCLKCTRL |= 1 << 16;
	
	ser_init();
	rfid_init();
	
	while(1)
	{
		int c;
		c = ser_getc();
		ser_putc(c);
		memset(rbuf,0,16);
		switch(c)
		{
			case 'r':
					rfid_read(rbuf);
					if(strlen((const char *)rbuf) < 16)
					{
						continue;
					}
					for(i = 0; i < 16; i++)
					{
						ser_putc(rbuf[i]);
					}
					break;
			case 'w':
					for(i = 0; i < 16; i++)
					{
						wbuf[i] = ser_getc();
					}
					rfid_write(wbuf);
					break;
		}
	}
}
